package com.tencent.listener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tencent.business.ScanPayBusiness;
import com.tencent.protocol.pay_protocol.ScanPayResData;
import com.tencent.protocol.pay_query_protocol.ScanPayQueryResData;

import cn.hl.hm.dao.RoadFeeMapper;


/**
 * User: rizenguo
 * Date: 2014/12/2
 * Time: 10:41
 *
 */
@Service
public class DefaultScanPayBusinessResultListener implements ScanPayBusiness.ResultListener{
    public static final String ON_FAIL_BY_RETURN_CODE_ERROR = "on_fail_by_return_code_error";
    public static final String ON_FAIL_BY_RETURN_CODE_FAIL = "on_fail_by_return_code_fail";
    public static final String ON_FAIL_BY_SIGN_INVALID = "on_fail_by_sign_invalid";

    public static final String ON_FAIL_BY_QUERY_SIGN_INVALID = "on_fail_by_query_sign_invalid";
    public static final String ON_FAIL_BY_REVERSE_SIGN_INVALID = "on_fail_by_query_service_sign_invalid";

    public static final String ON_FAIL_BY_AUTH_CODE_EXPIRE = "on_fail_by_auth_code_expire";
    public static final String ON_FAIL_BY_AUTH_CODE_INVALID = "on_fail_by_auth_code_invalid";
    public static final String ON_FAIL_BY_MONEY_NOT_ENOUGH = "on_fail_by_money_not_enough";

    private ScanPayResData resData ;//返回数据
    private ScanPayQueryResData payQueryResData;
    
    public ScanPayQueryResData getPayQueryResData() {
		return payQueryResData;
	}

	public void setPayQueryResData(ScanPayQueryResData payQueryResData) {
		this.payQueryResData = payQueryResData;
	}

	public ScanPayResData getResData() {
		return resData;
	}

	public void setResData(ScanPayResData resData) {
		this.resData = resData;
	}

	public static final String ON_FAIL = "on_fail";
    public static final String ON_SUCCESS = "on_success";

    private String result = "";
    private String transcationID = "";
    
	 public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getTranscationID() {
		return transcationID;
	}

	public void setTranscationID(String transcationID) {
		this.transcationID = transcationID;
	}

	public static String getOnFailByReturnCodeError() {
		return ON_FAIL_BY_RETURN_CODE_ERROR;
	}

	public static String getOnFailByReturnCodeFail() {
		return ON_FAIL_BY_RETURN_CODE_FAIL;
	}

	public static String getOnFailBySignInvalid() {
		return ON_FAIL_BY_SIGN_INVALID;
	}

	public static String getOnFailByQuerySignInvalid() {
		return ON_FAIL_BY_QUERY_SIGN_INVALID;
	}

	public static String getOnFailByReverseSignInvalid() {
		return ON_FAIL_BY_REVERSE_SIGN_INVALID;
	}

	public static String getOnFailByAuthCodeExpire() {
		return ON_FAIL_BY_AUTH_CODE_EXPIRE;
	}

	public static String getOnFailByAuthCodeInvalid() {
		return ON_FAIL_BY_AUTH_CODE_INVALID;
	}

	public static String getOnFailByMoneyNotEnough() {
		return ON_FAIL_BY_MONEY_NOT_ENOUGH;
	}

	public static String getOnFail() {
		return ON_FAIL;
	}

	public static String getOnSuccess() {
		return ON_SUCCESS;
	}

	/**
     * 遇到这个问题一般是程序没按照API规范去正确地传递参数导致，请仔细阅读API文档里面的字段说明
     */
	public void onFailByReturnCodeError(ScanPayResData scanPayResData) {
		  result = ON_FAIL_BY_RETURN_CODE_ERROR;	
	      resData = scanPayResData;

	}

	 /**
     * 同上，遇到这个问题一般是程序没按照API规范去正确地传递参数导致，请仔细阅读API文档里面的字段说明
     */
	public void onFailByReturnCodeFail(ScanPayResData scanPayResData) {
		 result = ON_FAIL_BY_RETURN_CODE_FAIL;
	     resData = scanPayResData;

	}

	 /**
     * 支付请求API返回的数据签名验证失败，有可能数据被篡改了。遇到这种错误建议商户直接告警，做好安全措施
     */
	public void onFailBySignInvalid(ScanPayResData scanPayResData) {
		 result = ON_FAIL_BY_SIGN_INVALID;		
	        resData = scanPayResData;

	}

	/**
     * 用户用来支付的二维码已经过期，提示收银员重新扫一下用户微信“刷卡”里面的二维码"
     */
	public void onFailByAuthCodeExpire(ScanPayResData scanPayResData) {
        result = ON_FAIL_BY_AUTH_CODE_EXPIRE;
        resData = scanPayResData;

	}

	@Override
	public void onFailByAuthCodeInvalid(ScanPayResData scanPayResData) {
        result = ON_FAIL_BY_AUTH_CODE_INVALID;
        resData = scanPayResData;

	}

	@Override
	public void onFailByMoneyNotEnough(ScanPayResData scanPayResData) {
        result = ON_FAIL_BY_MONEY_NOT_ENOUGH;
        resData = scanPayResData;

	}

	@Override
	public void onFail(ScanPayResData scanPayResData) {
        result = ON_FAIL;
        resData = scanPayResData;

	}

	@Override
	public void onSuccess(ScanPayResData scanPayResData) {
        result = ON_SUCCESS;
        resData = scanPayResData;
        transcationID = scanPayResData.getTransaction_id();
	}
	
}
